package com.youchuang.service;


import com.youchuang.entity.Account;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class DomainUserDetailsService implements UserDetailsService {


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Account account = new Account();
        account.setId("1");
        account.setUserName("cwq");
        account.setPassWord("123456");
        account.setRoles(new String[]{"ROLE_ADMIN", "ROLE_USER"});
        if (account != null) {
            return new User(account.getUserName(), account.getPassWord(), AuthorityUtils.createAuthorityList(account.getRoles()));
        } else {
            throw new UsernameNotFoundException("用户[" + username + "]不存在");
        }
    }
}
